package org.apache.lucene.ocean;

import org.apache.commons.lang.builder.CompareToBuilder;

/**
 * Id and type combine to make the IndexID
 *
 */
public class IndexID implements Comparable<IndexID> {
  public final Long id;
  public final String type;
  
  public IndexID(Long id, String type) {
    this.id = id;
    this.type = type;
  }
  
  public String toString() {
    return type+":"+id;
  }
  
  public int compareTo(IndexID other) {
    return new CompareToBuilder().append(id, other.id).append(other.type, type).toComparison();
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((id == null) ? 0 : id.hashCode());
    result = prime * result + ((type == null) ? 0 : type.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    final IndexID other = (IndexID) obj;
    if (id == null) {
      if (other.id != null)
        return false;
    } else if (!id.equals(other.id))
      return false;
    if (type == null) {
      if (other.type != null)
        return false;
    } else if (!type.equals(other.type))
      return false;
    return true;
  }
}
